package com.blog.dao.impl;

import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import com.blog.dao.IUserDao;
import com.blog.pojo.User;

public class UserDaoImpl implements IUserDao {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	@Override
	public boolean login(User user) {
		// "select * from tbl_users where (BINARY user_name = ? or BINARY reg_email = ?)and BINARY user_pwd = ? ";
		try {
			String sql = "select * from tbl_users where BINARY BINARY reg_email = ? and BINARY user_pwd = ? ";
			System.out.println(user.getRegEmail()+"----"+user.getUserPwd() );
			Map<String, Object> map = this.jdbcTemplate.queryForMap(sql,
					new Object[] { user.getRegEmail(), user.getUserPwd() });
			if (null != map) {
				return true;
			}
			return false;
		} catch (EmptyResultDataAccessException e) {
			e.printStackTrace();
			return false;
		}
	}
}
